import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter_with_bmap/entity/green_wave.dart';
import 'package:flutter_with_bmap/entity/green_wave_phase.dart';
import 'package:flutter_with_bmap/entity/light_hv.dart';
import 'package:flutter_with_bmap/entity/vehicle.dart';

class VehicleHvInfo extends ChangeNotifier {
  Vehicle? _info;
  Timer? _timer1;
  Timer? _timer2;
  LightHv? _lightInfo;
  GreenWave? _greenWave;
  Vehicle? get info => _info;
  LightHv? get lightInfo => _lightInfo;
  GreenWave? get greenWave => _greenWave;
  void setVehicleInfo(Vehicle info) {
    _info = info;
    notifyListeners();
  }

  void setLightInfo(LightHv? lightInfo) {
    _lightInfo = lightInfo;
    notifyListeners();
    // if (_timer1?.isActive ?? false) {
    //   _timer1!.cancel();
    // }
    _timer1?.cancel();
    _timer1 = Timer(const Duration(seconds: 2), (() {
      setLightInfo(null);
    }));
  }

  void setGreenWave(GreenWave? greenWave) {
    _greenWave = greenWave;
    notifyListeners();
    _timer2?.cancel();
    _timer2 = Timer(const Duration(seconds: 2), (() {
      setGreenWave(null);
    }));
  }
}
